package com.coder520.user.service;

import com.coder520.common.utils.SecurityUtils;
import com.coder520.user.dao.UserMapper;
import com.coder520.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

/**
 * Created by vern on 2017/9/13.
 */

@Service("userServiceImpl")
public class UserServiceImpl implements  UserService{

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户名查询用户
     * @param username
     */
    @Override
    public User findUserByusername(String username) {
       User user =  userMapper.selectByUserName(username);
        return user;
    }

    /**
     * 新增用户，MD5处理密码加密
     * @param user
     * @throws UnsupportedEncodingException
     * @throws NoSuchAlgorithmException
     */
    @Override
    public void creatUser(User user) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        user.setPassword(SecurityUtils.encrptyPassword(user.getPassword()));
        userMapper.insertSelective(user);
    }
}
